import 'dart:convert';
import 'package:financing_wallet/route_config.dart';
import 'package:financing_wallet/themes.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:flutter_network/service_url.dart';
import 'package:get/get.dart';
import 'package:wallet_utils/base_router_config.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:wallet_utils/over_scroll_behavior.dart';
import 'main_config.dart';
import 'package:flutter/cupertino.dart';



void main() async {
  MainConfig.init();
  runApp(const BaseApp());
}

class BaseApp extends StatefulWidget {
  const BaseApp({Key? key}) : super(key: key);

  @override
  _BaseAppState createState() => _BaseAppState();
}

class _BaseAppState extends State<BaseApp> {
  //statusBar设置为透明，去除半透明遮罩
  final SystemUiOverlayStyle _style =
  const SystemUiOverlayStyle(statusBarColor: Colors.transparent);
  final MethodChannel _methodChannel = const MethodChannel('native');

  @override
  void initState() {
    super.initState();
    _methodChannel.invokeMethod("ENVIRONMENT").then((enviroment) async {
      Map<String, dynamic> enMap = json.decode(enviroment);
      SharedPreferences preferences = await SharedPreferences.getInstance();
      preferences.setString("ENVIRONMENT", enMap['ENVIRONMENT']);
      switch (enMap['ENVIRONMENT']) {
        case "DEV":
          // baseUrl = "http://192.168.3.129:19011/"; //主base地址
          // webBaseUrl='https://h5.rongeqb.com/';
          baseUrl = "http://39.96.173.145:19011/"; //主base地址
          webBaseUrl='https://h5.rongeqb.com/';
          break;
        case "BETA":
          baseUrl = "http://39.96.173.145:19011/"; //主base地址
          webBaseUrl='https://h5.rongeqb.com/';
          // baseUrl = "https://app.rongeqb.com/"; //主base地址
          // webBaseUrl='https://h5.rongeqb.com/';
          break;
        case "PRE":
          baseUrl = "http://39.96.173.145:19011/"; //主base地址
          webBaseUrl='https://h5.rongeqb.com/';
//           baseUrl = "https://app.rongeqb.com/"; //主base地址
//           webBaseUrl='https://h5.rongeqb.com/';
          break;
        case "APPSTORE":
          // baseUrl = "https://app.rongeqb.com/"; //主base地址
          // webBaseUrl='https://h5.rongeqb.com/';
          baseUrl = "http://39.96.173.145:19011/"; //主base地址
          webBaseUrl='https://h5.rongeqb.com/';
          break;
        default:
          // baseUrl = "https://app.rongeqb.com/"; //主base地址
          // webBaseUrl='https://h5.rongeqb.com/';
          baseUrl = "http://39.96.173.145:19011/"; //主base地址
          webBaseUrl='https://h5.rongeqb.com/';
          break;
      }
    });


  }

  @override
  Widget build(BuildContext context) {
    SystemChrome.setSystemUIOverlayStyle(_style);

    return GetMaterialApp(
      theme: Themes.mainTheme,
      scrollBehavior: OverScrollBehavior(),
      defaultTransition: Transition.cupertino,
      transitionDuration: const Duration(milliseconds: 500),
      //国际化
      localizationsDelegates: const [
        GlobalMaterialLocalizations.delegate,
        GlobalWidgetsLocalizations.delegate,
        GlobalCupertinoLocalizations.delegate,
      ],
      supportedLocales: const [
        Locale('zh', 'CN'),
        Locale('en', 'US'),
      ],
      debugShowCheckedModeBanner: false,
      initialRoute: BaseRouterConfig.home,
      getPages: RouteConfig.getPages,
      title: '放鑫钱包',
    );
  }

}
